package co.yixiang.yshop.module.order.dal.mysql.storeaftersales;

import co.yixiang.yshop.framework.common.pojo.PageResult;
import co.yixiang.yshop.framework.mybatis.core.mapper.BaseMapperX;
import co.yixiang.yshop.framework.mybatis.core.query.LambdaQueryWrapperX;
import co.yixiang.yshop.module.order.controller.admin.storeaftersales.vo.StoreAfterSalesPageReqVO;
import co.yixiang.yshop.module.order.dal.dataobject.storeaftersales.StoreAfterSalesDO;
import co.yixiang.yshop.module.order.enums.AdminAfterOrderStatusEnum;
import co.yixiang.yshop.module.order.enums.AfterSalesStatusEnum;
import org.apache.ibatis.annotations.Mapper;

/**
 * 售后记录 Mapper
 *
 * @author yshop
 */
@Mapper
public interface StoreAfterSalesMapper extends BaseMapperX<StoreAfterSalesDO> {

    default PageResult<StoreAfterSalesDO> selectPage(StoreAfterSalesPageReqVO reqVO) {
        LambdaQueryWrapperX<StoreAfterSalesDO> wrapper = new LambdaQueryWrapperX();
        wrapper.eqIfPresent(StoreAfterSalesDO::getOrderCode, reqVO.getOrderCode())
                .orderByDesc(StoreAfterSalesDO::getId);
        if (reqVO.getType() != null && reqVO.getType() != -1) {
            switch (AdminAfterOrderStatusEnum.toType(reqVO.getType())) {
                //售后中
                case AFTER_SALES:
                    wrapper.ne(StoreAfterSalesDO::getState, AfterSalesStatusEnum.REFUND_SUCCESS.getValue());
                    break;
                //已完成
                case COMPLETED:
                    wrapper.eq(StoreAfterSalesDO::getState, AfterSalesStatusEnum.REFUND_SUCCESS.getValue());
                    break;

                default:
            }
        }
        return selectPage(reqVO, wrapper);
    }


}
